package com.qingjiang.projectschedule.service.impl;

import com.qingjiang.projectschedule.pojo.ProjectQueryCond;
import com.qingjiang.projectschedule.service.ProjectInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Calendar;

@Service
public class ScheduledAccess {
    @Autowired
    private ProjectInformationService projectInformationService;

    @Scheduled(cron = "0 04 23 25 * ?")
    public void recordAccessStatus() {
        System.out.println("定时任务执行！！！！！");
        //刷新25号各项目状态
        ProjectQueryCond queryCond = new ProjectQueryCond();
        projectInformationService.queryByCond(queryCond);

        //保存当月25号及之前的统计数据
        Calendar instance = Calendar.getInstance();
        int curYear = instance.get(Calendar.YEAR);
        int curMonth = instance.get(Calendar.MONTH) + 1;
        projectInformationService.getProjectStatisticByYearAndMonth(curYear, curMonth, true);

        //将已完成项目的 isFinish 字段修改为 1
        projectInformationService.updateProjectForFinish();
    }
}
